package com.example.giftrecord.controller;

import com.example.giftrecord.model.BaseResponse;
import com.example.giftrecord.model.LoginRequest;
import org.springframework.web.bind.annotation.*;

import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

@RestController
@RequestMapping("/login")
@CrossOrigin(origins = "*") // 允许跨域访问，实际生产环境应限制来源
public class LoginController {
    public static final Set<String> tokenSet = new HashSet<>();

    @PostMapping
    public BaseResponse login(@RequestBody LoginRequest request) {
        if ("admin".equals(request.getUsername()) && "adminqazxsw123".equals(request.getPassword())) {
            String replace = UUID.randomUUID().toString().replace("-", "");
            tokenSet.add(replace);
            return BaseResponse.success(replace);
        } else {
            return BaseResponse.errorMsg("用户名或密码错误");
        }
    }
}
